﻿//Packet for compressed Image
namespace Compression.ImageCompressor
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    [Serializable]
    public class ImagePacket
    {
        List<WaveletPoint> a,b,c;        

        public ImagePacket(){
            a = new List<WaveletPoint>();
            b = new List<WaveletPoint>();
            c = new List<WaveletPoint>();
        }

        public List<WaveletPoint> FirstCollection
        {
            get
            {
                return a;
            }
            set
            {
                a = value;
            }
        }

        public List<WaveletPoint> SecondCollection
        {
            get
            {
                return b;
            }
            set
            {
                b = value;
            }
        }

        public List<WaveletPoint> ThridCollection
        {
            get
            {
                return c;
            }
            set
            {
                c = value;
            }
        }

        public void SavePacket(FileWorker worker){
            worker.Write(a.Count);
            for (int i=0;i<a.Count;i++){
                worker.Write(a[i].Cnt);
                worker.Write(a[i].Value);
            }
            worker.Write(b.Count);
            for (int i = 0; i < b.Count; i++)
            {
                worker.Write(b[i].Cnt);
                worker.Write(b[i].Value);
            }
            worker.Write(c.Count);
            for (int i = 0; i < c.Count; i++)
            {
                worker.Write(c[i].Cnt);
                worker.Write(c[i].Value);
            }
        }

        public void LoadPacket(FileWorker worker)
        {
            int size = worker.ReadInt32();
            a.Clear();
            for (int i = 0; i < size; i++)
            {
                UInt32 cnt = worker.ReadUInt32();
                Int16 val = worker.ReadInt16();
                a.Add(new WaveletPoint(cnt,val));
            }
            size = worker.ReadInt32();
            b.Clear();
            for (int i = 0; i < size; i++)
            {
                UInt32 cnt = worker.ReadUInt32();
                Int16 val = worker.ReadInt16();
                b.Add(new WaveletPoint(cnt, val));
            }
            size = worker.ReadInt32();
            c.Clear();
            for (int i = 0; i < size; i++)
            {
                UInt32 cnt = worker.ReadUInt32();
                Int16 val = worker.ReadInt16();
                c.Add(new WaveletPoint(cnt, val));
            }
        }
    }
}
